package com.zhong.gang.app.ui.login;


import android.text.TextUtils;
import android.view.View;
import androidx.annotation.NonNull;
import com.luck.picture.lib.tools.ToastUtils;
import com.zhong.gang.app.R;
import com.zhong.gang.app.databinding.ActivityChangePassBinding;
import com.zhong.gang.app.db.UserUtils;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.applib.utils.CheckedUtils;

public class ChangePassAct extends ActBase<ActivityChangePassBinding> {
    private LoginPresenter presenter;

    @Override
    public int LayoutRes() {
        return R.layout.activity_change_pass;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "修改密码";
    }

    @Override
    public void initView() {
        bind.setAct(this);
        presenter = new LoginPresenter();
        bind.name.setText(UserUtils.getIntent(this).getUser().getName());
    }

    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.sure:
                if (checkInputIsOK()){
                    presenter.changePass(this,bind.nowPass.getText().toString(),bind.newPass.getText().toString());
                }
                break;
        }
    }

    public boolean checkInputIsOK(){
        String nowPass = bind.nowPass.getText().toString();
        String newPass = bind.newPass.getText().toString();
        String reNewPas = bind.reNewPass.getText().toString();
        if (TextUtils.isEmpty(nowPass)){
            CheckedUtils.shakeAnimation(bind.nowPass,3);
            ToastUtils.s(this,"请输入当前密码");
            return false;
        }

        if (TextUtils.isEmpty(newPass)){
            CheckedUtils.shakeAnimation(bind.newPass,3);
            ToastUtils.s(this,"请输入新密码");
            return false;
        }
        if (!CheckedUtils.isSome(newPass,reNewPas)){
            CheckedUtils.shakeAnimation(bind.reNewPass,3);
            ToastUtils.s(this,"两次输入的密码不相同");
            return false;
        }
        return true;
    }
}
